package com.pj.wisdomlogistics.ui.adapter;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.pj.wisdomlogistics.R;
import com.pj.wisdomlogistics.entity.CarPoritionInfo;
import com.pj.wisdomlogistics.ui.view.SquareRelativeLayout;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseAdapter;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseViewHolder;
import com.zhy.autolayout.utils.AutoUtils;

public class CarFreeAdapter extends BaseAdapter<CarPoritionInfo.CarListBean, BaseViewHolder> {

    public CarFreeAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder createCustomViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(parent, R.layout.item_choose_car);
    }

    @Override
    public void bindCustomViewHolder(final BaseViewHolder viewHolder, final int position) {
        AutoUtils.autoSize(viewHolder.itemView);

        final CarPoritionInfo.CarListBean item = getItem(position);
        viewHolder.getTextView(R.id.tv_car_model).setText(item.getCarModel());
        viewHolder.getTextView(R.id.tv_car_num).setText(item.getCarNum());
        viewHolder.getTextView(R.id.tv_car_seat).setText(item.getSeat());

        final SquareRelativeLayout layout = viewHolder.getView(R.id.rel_choose_car);
        if(item.getState() == 1){
            layout.setBackgroundResource(R.drawable.select_car_2);
        }

        viewHolder.getView(R.id.rel_choose_car).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClick.itemClick(position ,item.getState() , layout);
            }
        });

    }

    @Override
    public int getCustomViewType(int position) {
        return 0;
    }


    public onItemClick mOnItemClick;

    public interface onItemClick {
        public void itemClick(int position ,int state ,  View mView);
    }

    public void setListener(onItemClick mListener) {
        this.mOnItemClick = mListener;
    }

}
